#e
#Title[u-156x̐Uv]
#Text[]
#ScriptVersion[2]

script_enemy_main {
    let imgBoss = GetCurrentScriptDirectory~".\chirno.png";

    @Initialize {
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
        SetGraphicRect(0, 0, 63, 63);
        SetLife(4500);
        SetTimer(80);
        SetScore(4000000);
        CutIn(YOUMU,"u-156x̐Uv", "", 0, 0, 0, 0);
        SetInvincibility(800);
        Tshot;
        Tshot2;
        TMove; 
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 24);
        SetCollisionB(GetX, GetY, 24);

        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    task Tshot{
        yield;
       loop(100){yield;}
         let id = 1;
       loop{
         Concentration02(100);
         loop(100){yield;}
         loop(100){
              let x = rand(0,448);
              let y = rand(0,480);
              CreateShotA(id,x,y,1);
              SetShotDataA(id,0,0,0,0,0,0,AQUA02);
              SetShotDataA(id,rand_int(1,3)*50,0.2,rand(0,360),0,0,0,BLUE02);
              SetShotDataA(id,rand_int(3,8)*50,0.2,rand(0,360),0,0,0,BLUE02);
              SetShotDataA(id,rand_int(8,12)*50,0.2,rand(0,360),0,0,0,BLUE02);
	      if(x > GetPlayerX+40 || x < GetPlayerX-40  || y > GetPlayerY+40 || y < GetPlayerY-40 )
              {
              FireShot(id);
              }
              id ++;
            }
         loop(500){yield;}
         }
      }

   task Tshot2{
        yield;
       loop(100){yield;}
         let id2 = 1000000;
       loop{
         Concentration02(100);
         loop(100){yield;}
         loop(150){
              let x = rand(0,448);
              let y = rand(0,480);
              CreateShotA(id2,x,y,1);
              SetShotDataA(id2,0,0,0,0,0,0,AQUA01);
              SetShotDataA(id2,rand_int(1,3)*40,0.2,rand(0,360),0,0,0,BLUE01);
              SetShotDataA(id2,rand_int(3,8)*40,0.2,rand(0,360),0,0,0,BLUE01);
              SetShotDataA(id2,rand_int(8,11)*40,0.2,rand(0,360),0,0,0,BLUE01);
	      SetShotDataA(id2,rand_int(11,15)*40,0.2,rand(0,360),0,0,0,BLUE01);
           if(x > GetPlayerX+30 || x < GetPlayerX-30  || y > GetPlayerY+30 || y < GetPlayerY-30 )
              {
              FireShot(id2);
              }
              id2 ++;
            }
         loop(500){yield;}
         }
      }

    sub standBy {

        SetMovePosition02(228, 136, 30);
        setGraphicMove;
        loop(30){yield;}
        setGraphicStop;
        loop(70){yield;}
    }

    sub setGraphicStop  { SetGraphicRect(  0,   0, 128, 128); }
    sub setGraphicLeft  { SetGraphicRect(256,   0, 384, 128); }
    sub setGraphicRight { SetGraphicRect(256, 256, 384, 384); }

    sub setGraphicMove {
        if(GetSpeedX < 0) {
            setGraphicLeft;
        } else {
            setGraphicRight;
        }
    }
    task TMove {
        yield;
        standBy;
        loop(100){yield;}
        loop {
            loop(60) { yield; }
            moveToPlayer(rand(10, 20), rand(-40, 40), 60,
                         GetClipMinX + 32, GetClipMinY + 32,
                         GetClipMaxX - 32, GetClipMinY + 160);
            setGraphicMove;
            loop(60){yield;}
            setGraphicStop;
        }
    }

    function nway(dir, way, span, color) {

        let radius = 32;


        let angle  = dir - (way - 1) / 2 * span;

        loop(way) {

            CreateShot01(GetX, GetY, 1, angle, color, 0);
            angle += span;
        }
    }



    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX) {

            x = GetX - xMove;

            if(x < left) {
                x = GetX + xMove;
            }
        } else {

            x = GetX + xMove;


            if(right < x) {
                x = GetX - xMove;
            }
        }

        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }
}